home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Includes / UTracker.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  6.6 KB  |  176 lines  |  [TEXT/MPS ]

  1. // UTracker.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4.  
  5. #ifndef __UTRACKER__
  6. #define __UTRACKER__
  7.  
  8. // MacApp
  9.  
  10. #ifndef __UCOMMAND__
  11. #include "UCommand.h"
  12. #endif
  13.  
  14. #ifndef __UGEOMETRY__
  15. #include "UGeometry.h"
  16. #endif
  17.  
  18. //----------------------------------------------------------------------------------------
  19. // Forward and external class declarations. 
  20. //----------------------------------------------------------------------------------------
  21.  
  22. class TScroller;
  23. class TView;
  24.  
  25. //----------------------------------------------------------------------------------------
  26. // TTracker: Handles a user command, including undoing and mouse-tracking if required.
  27. // Usually created by the part of the Application with the greatest specific knowledge
  28. // about the action to take in response to events and passed back to be performed at
  29. // several well defined places.
  30. //----------------------------------------------------------------------------------------
  31.  
  32. class TTracker : public TCommand
  33. {
  34.     MA_DECLARE_CLASS;
  35.     
  36. public:
  37.     TTracker();
  38.         // Empty constructor to satisfy compiler.
  39.     virtual ~TTracker();
  40.         // Destructor
  41.         
  42.     TView* fView;                                // The view in which tracking takes place
  43.  
  44.     VPoint fInitialPt;                            // Where to track from (usually where the
  45.                                                 // mouse went down).In coordinates of the
  46.                                                 // fView (that's being tracked) else if
  47.                                                 // the fView is NULL in global coordinates.
  48.  
  49.     Boolean fConstrainsMouse;                    // Defaults to false; if you set to true
  50.                                                 // then TrackConstrain will be called to
  51.                                                 // constrain the mouse.  
  52.  
  53.     Boolean fViewConstrain;                        // Defaults to true, which means constrain
  54.                                                 // mouse to view limits  
  55.  
  56.     Boolean fTrackNonMovement;                    // Defaults to false, which means don't
  57.                                                 // track mouse unless it moves.  
  58.  
  59.     TScroller* fScroller;                        // The scroller that handles
  60.                                                 // auto-scrolling  
  61.  
  62.     TrackPhase fTrackPhase;
  63.  
  64.     VPoint fAnchorPoint;
  65.     VPoint fPreviousPoint;
  66.     VPoint fNextPoint;
  67.  
  68.     VPoint fLastAnchorPoint;
  69.     VPoint fLastPreviousPoint;
  70.     VPoint fLastNextPoint;
  71.  
  72.     GrafPtr fDeskTopTrackingPort;
  73.     CPoint fHysteresis;
  74.     Boolean fMovedOnce;
  75.  
  76.     //------------------------------------------------------------------------------------
  77.     // Init & Free  
  78.     //------------------------------------------------------------------------------------
  79.  
  80.     void ITracker(CommandNumber itsCommandNumber,
  81.                   TCommandHandler* itsContext,
  82.                   Boolean canUndo,
  83.                   Boolean causesChange,
  84.                   TObject* objectToNotify,
  85.                   TView* itsView,
  86.                   TScroller* itsScroller,
  87.                   const VPoint& itsMouse);
  88.         // Initialize a command procedurally.  
  89.  
  90.  
  91.     //------------------------------------------------------------------------------------
  92.     // Command Processing  
  93.     //------------------------------------------------------------------------------------
  94.     
  95.     virtual void Process(); // Override
  96.         // Overridden to call TApplication::TrackMouse.  
  97.  
  98.  
  99.     //------------------------------------------------------------------------------------
  100.     // Mouse Tracking  
  101.     //------------------------------------------------------------------------------------
  102.  
  103.     virtual Boolean IsDoneTracking();
  104.         // Indicates whether the Command is through tracking. (the command is also through
  105.         // tracking if you return NULL from TrackMouse). Defaults to fView->IsDoneTracking.
  106.         // Most programs won't have to mess with this. NOTE you still have to deal with
  107.         // queued events if you change the criteria for true.  
  108.  
  109.     virtual void TrackConstrain(TrackPhase aTrackPhase,
  110.                                 const VPoint& anchorPoint,
  111.                                   const VPoint& previousPoint,
  112.                                 VPoint& nextPoint,
  113.                                 Boolean mouseDidMove);
  114.         // Override this if you want to constrain the mouse CPoint to a grid, force drawing
  115.         // a square, etc. This is called only if fConstrainsMouse is true.  
  116.  
  117.     virtual void TrackFeedback(TrackPhase aTrackPhase,
  118.                                const VPoint& anchorPoint,
  119.                                const VPoint& previousPoint,
  120.                                const VPoint& nextPoint,
  121.                                Boolean mouseDidMove,
  122.                                Boolean turnItOn);
  123.         // Default is: IF NOT mouseDidMove THEN FrameRect(<CRect formed by anchorPoint and
  124.         // nextPoint>). Before this is called the pen is set to PenNormal and the PenMode
  125.         // to PatXOR.  
  126.  
  127.     virtual TTracker* TrackMouse(TrackPhase aTrackPhase,
  128.                                  VPoint& anchorPoint,
  129.                                  VPoint& previousPoint,
  130.                                  VPoint& nextPoint,
  131.                                  Boolean mouseDidMove);
  132.         // This does the mouse tracking. The default returns this. Override it to force
  133.         // gridding, to return a different type of command, or to perform the command on
  134.         // mouse release instead of using the usual DoIt approach. All points are in local
  135.         // coordinates. If aTrackPhase = trackPress then all 3 points will be the same. If
  136.         // aTrackPhase = trackRelease then nextPoint will be the coordinate in the mouseUp
  137.         // event (if a mouseUp event is found), otherwise the same CPoint as previousPoint.
  138.         // Generally, you will ignore nextPoint and just look at previousPoint.
  139.         // mouseDidMove will be true if aTrackPhase = trackPress or trackRelease;
  140.         // otherwise, it will indicate if nextPoint = previousPoint. If you change
  141.         // anchorPoint, the new value will be passed to you next time. The value of
  142.         // nextPoint at the time the routine exits will be passed to you as previousPoint
  143.         // the next time the routine is called. You can change nextPoint if you wish.
  144.         // Usually, however, you will do gridding in the TrackConstrain method.  
  145.  
  146.     virtual void AutoScroll(const VPoint& delta);
  147.         // Implements autoscrolling by calling fScroller->ScrollBy.  
  148.  
  149.  
  150.     //------------------------------------------------------------------------------------
  151.     // Managing the tracking.  You don't usually call these… MacApp does  
  152.     //------------------------------------------------------------------------------------
  153.  
  154.     virtual void CleanUpFocus();
  155.  
  156.     virtual void DoFocus();
  157.  
  158.     virtual void BecomeTracker(TTracker* oldTracker);
  159.  
  160.     virtual void FeedbackOnce(Boolean mouseDidMove,
  161.                               Boolean turnItOn);
  162.  
  163.     virtual void ConstrainOnce(Boolean didMouseMove);
  164.  
  165.     virtual TTracker* TrackOnce(Boolean didMouseMove);
  166.  
  167.     virtual TTracker* HandleTrackBegin(const VPoint& theMouse, CPoint hysteresis);
  168.  
  169.     virtual TTracker* HandleTrackContinue();
  170.  
  171.     virtual TTracker* HandleTrackEnd();
  172.  
  173. };
  174.  
  175.  
  176. #endif // __UTRACKER__